/**
 ******************************************************************************
 * @file    Project/STM32F4xx_StdPeriph_Templates/main.c 
 * @author  MCD Application Team
 * @version V1.6.1
 * @date    21-October-2015
 * @brief   Main program body
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
 *
 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *        http://www.st.com/software_license_agreement_liberty_v2
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************
 */

/* Includes ------------------------------------------------------------------*/
#ifndef	__BITFILTER_H__
#define __BITFILTER_H__

#include "stdint.h"


/* Private typedef -----------------------------------------------------------*/
typedef struct  {
    uint8_t	level        :1;                        //电平状态
    uint8_t	edge         :1;                        //边沿触发
    uint8_t	old_level    :1;                        //上一次电平
    uint8_t old_bit      :1;                        //上一次BIT值
    uint8_t nc           :4;                        //保留
    uint8_t	cnt;                                    //计数值
    uint8_t	low_cmp;                                //低电平比较值
    uint8_t	high_cmp;                               //高电平比较值
}bitfilter_t;



typedef enum  {
	BitLow = 0,
    BitHigh = 1,
    BitLowEdge = 2,
    BitHighEdge = 3
} BitFStatus;

#define BIT_LEVEL_MASK  1
#define BIT_EDGE_MASK   2
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


uint8_t mod_bitfilter_state(bitfilter_t *filter);

uint8_t mod_bitfilter_edge(bitfilter_t *filter);

uint8_t mod_bitfilter_level(bitfilter_t *filter);

void mod_bitfilter_init(bitfilter_t *filter ,uint8_t high_cmp, uint8_t low_cmp);

void mod_bitfilter_poll(uint8_t bit_val, bitfilter_t *filter);

#endif

/**
 * @}
 */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
